{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## OvR 和 OvO"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from sklearn import datasets\n",
    "\n",
    "iris = datasets.load_iris()\n",
    "X = iris.data[:,:2]\n",
    "y = iris.target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from sklearn.model_selection import train_test_split\n",
    "\n",
    "X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=666)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "LogisticRegression(C=1.0, class_weight=None, dual=False, fit_intercept=True,\n",
       "          intercept_scaling=1, max_iter=100, multi_class='ovr', n_jobs=1,\n",
       "          penalty='l2', random_state=None, solver='liblinear', tol=0.0001,\n",
       "          verbose=0, warm_start=False)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.linear_model import LogisticRegression\n",
    "\n",
    "log_reg = LogisticRegression()\n",
    "log_reg.fit(X_train, y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.65789473684210531"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "log_reg.score(X_test, y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def plot_decision_boundary(model, axis):\n",
    "    \n",
    "    x0, x1 = np.meshgrid(\n",
    "        np.linspace(axis[0], axis[1], int((axis[1]-axis[0])*100)).reshape(-1, 1),\n",
    "        np.linspace(axis[2], axis[3], int((axis[3]-axis[2])*100)).reshape(-1, 1),\n",
    "    )\n",
    "    X_new = np.c_[x0.ravel(), x1.ravel()]\n",
    "\n",
    "    y_predict = model.predict(X_new)\n",
    "    zz = y_predict.reshape(x0.shape)\n",
    "\n",
    "    from matplotlib.colors import ListedColormap\n",
    "    custom_cmap = ListedColormap(['#EF9A9A','#FFF59D','#90CAF9'])\n",
    "    \n",
    "    plt.contourf(x0, x1, zz, linewidth=5, cmap=custom_cmap)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXwAAAD8CAYAAAB0IB+mAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3X2QXHWd7/H3dx7MjJMJYxZCQgKb3AJ1NSCRVGTFB/Cp\nNhFNStkqb6kotddcLaXwui73snhltaSsxVteWdgrFfUqrK5bGjBxMViKRgW8QCXBDYGgshsxCXlQ\nIclMmMHMzPf+0d2Tnk73Oaf79OnT55zPqyrF9Hno/vWZ4Tu/+fWnv23ujoiI5F9P2gMQEZHOUMEX\nESkIFXwRkYJQwRcRKQgVfBGRglDBFxEpiMgF38x6zewRM7u7zr5Lzeyomf2i/O+T7R2miIjE1dfE\nsdcAu4F5Dfbf5+6Xxx+SiIgkIdIM38yWAG8FvpzscEREJClRZ/hfAK4FhgOOebWZ7QT2Ax9398dq\nDzCz9cB6gKE5cy46b+HCJocrItI5vfPh8PifpD2MWfY+seP37n5GK+eGFnwzuxw47O7bzezSBoft\nAM5x9zEzWwNsAs6rPcjdNwAbAFYsXepbr7++lTGLiCRu5N293PzYe9Iexik+umrOU62eG2WGfwnw\n9nIhHwDmmdnX3X3mSrj7saqvt5jZ/zGz0939960OTEQkLbdf+D44ZY0i+0ILvrtfB1wHpTQOpeWa\nWb/2zGwhcMjd3cxWUXpt4A/tH66ISHJuv/B9aQ8hUc2kdGYxsw8CuPttw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+ZqngX8M0629P6mYLGY4IOXid33w/8L+C3wAHgqLv/oOawjl+niOOCJq9VogXf\nzC4HDrv79iQfpxkRx7QDOMfdLwBuATZ1YGivcfcLgdXAh83sdR14zCjCxtXpa9UHvBL4oruvAI4D\n/yPhxwwTZUxp/ExhZi8A3g58uxOPF0XImDp6nczsRZRm8MuAs4AhM0u9G2HEcTV9rZKe4V8CvN3M\nfgP8C/AGM/t6zTH7gbOrbi8pb0ttTJ5Cu4jyb3Tc/TDwHWBVzSGdvk6RxpXCtdoH7HP3h8q3N1Iq\nttU6fa1Cx5TGz1TZamCHux+qsy+Vn6mgMaVwnd4E7HH337n7CeAu4NU1x6RxnULH1cq1SrTgu/t1\n7r7E3ZdS+hPux+5e+1vqu8CV5VfCL6b0p8uBNMdkHW4XYWZDZjZc+Rp4C1DbSbSj1ynquDp9rdz9\nILDXzCodA98IPF5zWKd/pkLH1OnrVOU/03jppOM/U2FjSuE6/Ra42MxeWH7cNwK7a45J4zqFjquV\na9Wu9shNMbMPwkxrhi2UXgV/EngOuKoLxtRqu4hWnQl8p/y96wP+2d2/3wXXKcq4On2tAK4GvlFe\nGvgP4KouuFZhY+r4dSr/kn4z8F+rtqV6nSKMqaPXyd0fMrONlJZHJoFHgA1pX6eI42r6Wqm1gohI\nQeidtiIiBaGCLyJSECr4IiIFoYIvIlIQKvgiIgWhgi8iUhAq+CIiBfH/ATEWteO3grl8AAAAAElF\nTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1110bca20>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_decision_boundary(log_reg, axis=[4, 8.5, 1.5, 4.5])\n",
    "plt.scatter(X[y==0,0], X[y==0,1])\n",
    "plt.scatter(X[y==1,0], X[y==1,1])\n",
    "plt.scatter(X[y==2,0], X[y==2,1])\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.78947368421052633"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "log_reg2 = LogisticRegression(multi_class=\"multinomial\", solver=\"newton-cg\")\n",
    "log_reg2.fit(X_train, y_train)\n",
    "log_reg2.score(X_test, y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXwAAAD8CAYAAAB0IB+mAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3X+Q3HWd5/Hne36QjJNJBjaECQkRqkCMZBE0Fblk10L8\nURIooRS2uEJdqb2NWkrFc3etY7EEOSlryyvPLFyJUe/UxdWTkAVPBks94MSkApUEhMCgyy5CEiYJ\nCEkmyQQy6ff90T2Tmab7++3ub3/6+/12vx5VU0x/f/T3PV8m73zz7Ve/29wdERFpf11pFyAiIq2h\nhi8i0iHU8EVEOoQavohIh1DDFxHpEGr4IiIdouaGb2bdZvaYmf2swrqLzeyAmT1e+vpSc8sUEZGk\neurYdi0wAsytsv5hd788eUkiIhJCTVf4ZrYYuAz4TthyREQklFqv8L8BfAEYiNhmpZk9AewG/tbd\nnyrfwMzWAGsA+mfNeuc5Q0N1livSvv7Y9ydplyA5sPOZ7S+7+6mN7Bvb8M3scmCfu28zs4urbLYd\nWOLuh8xsNXAPcE75Ru6+HlgPcOGZZ/qDN97YSM0ibef7F/xl2iVITnxuxaznG923lls6q4APmdkf\ngB8Dl5jZndM3cPeD7n6o9P0w0Gtm8xstSqSTDF7bnXYJ0iFiG7673+Dui939TOAa4AF3/+j0bcxs\nyMys9P2K0vP+MUC9Im1n3VMfjd9IpAnqSenMYGafAnD3O4CrgE+b2QQwDlzjGsMpEku3cqSV6mr4\n7v4Q8FDp+zumLb8duL2ZhUn7GR7r47ZXBtgz0c1Qz3GuP2WM1QPjaZeVGjV7aTW901ZaYnisj1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7+d9SPwU+Xnol/CKK/3QZTbMma/G4\nCDPrN7OBye+BDwDlk0Rbep5qravV58rd9wA7zWxyYuB7gafLNmv171RsTa0+T9P8R6rfOmn571Rc\nTSmcpxeAi8zsTaXjvhcYKdsmjfMUW1cj56pZ45HrYmafgqnRDMMUXwV/FjgCXJeBmhodF9Go04B/\nKf2/6wH+2d1/noHzVEtdrT5XANcDPyzdGvh34LoMnKu4mlp+nkp/Sb8f+OS0Zamepxpqaul5cvdH\nzGwDxdsjE8BjwPq0z1ONddV9rjRaQUSkQ+idtiIiHUINX0SkQ6jhi4h0CDV8EZEOoYYvItIh1PBF\nRDqEGr6ISIf4/xl8m2y/Zo6lAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1110bc3c8>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_decision_boundary(log_reg2, axis=[4, 8.5, 1.5, 4.5])\n",
    "plt.scatter(X[y==0,0], X[y==0,1])\n",
    "plt.scatter(X[y==1,0], X[y==1,1])\n",
    "plt.scatter(X[y==2,0], X[y==2,1])\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 使用所有的数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "X = iris.data\n",
    "y = iris.target\n",
    "\n",
    "X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=666)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.94736842105263153"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "log_reg = LogisticRegression()\n",
    "log_reg.fit(X_train, y_train)\n",
    "log_reg.score(X_test, y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.0"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "log_reg2 = LogisticRegression(multi_class=\"multinomial\", solver=\"newton-cg\")\n",
    "log_reg2.fit(X_train, y_train)\n",
    "log_reg2.score(X_test, y_test)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### OvO and OvR"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.94736842105263153"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.multiclass import OneVsRestClassifier\n",
    "\n",
    "ovr = OneVsRestClassifier(log_reg)\n",
    "ovr.fit(X_train, y_train)\n",
    "ovr.score(X_test, y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.0"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.multiclass import OneVsOneClassifier\n",
    "\n",
    "ovo = OneVsOneClassifier(log_reg)\n",
    "ovo.fit(X_train, y_train)\n",
    "ovo.score(X_test, y_test)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
